<?php



$usernames=array(
    "baidu"=>"李彦宏",
    "马云",
   '360'=> "周鸿祎"
);
#数组如果有键,就用剑,没有写键的从0开始




print_r($usernames);

echo $usernames['baidu'];
echo " ".$usernames['360'];




$userAge=array(
    
    "武器"=>5
    
);
echo " ".$userAge['武器'];
#php支持中文下标

$userAge['方法']=66;
echo "  ".$userAge['方法']." ";
print_r($userAge);
#不是数字下标不能用for遍历



$info =array("咖啡","荼","牛奶");

list($drin,$bower,$power)=$info;

echo $drin."  ".$bower." ".$power;


$info =array("啡","水","牛");

list($drin1,,$power1)=$info;

echo "\n".$drin1."    ".$power1;
list($dr)=$info;
#list解组:把数组提取成变量,
#多次使用数组里面某个值时可以提高效率

echo "\n".$dr."    ";


$info =array("啡"=>25,"水"=>23,"牛"=>22);

list($a,$b,$c)=$info;
echo"---------------\n";
var_dump($a, $b,$c);
echo"---------------\n";



function function_name() {
    $size = "large";
    $var_array = array("color" => "blue",
        "size"  => "medium",
        "shape" => "sphere");
    extract($var_array, EXTR_PREFIX_SAME, "wddx");
    #将数组变量提取到当前环境符号表
    #extract函数,可以用于函数且函数多次使用数组的值
    echo "$color, $size, $shape, $wddx_size\n";;
}

function_name();
echo "";

//include 'study/数组/定义.php';
//deprecated

$arr2=array(10,1,2,3);
foreach ($arr2 as $k=> &$vv){
    $arrat[$k]=$vv;
}
#foreach引用时要重置指针
#要unset(遍历的值)
reset($arr2);#重置指针
unset($vv);#要unset(遍历的值)
var_dump(current($arr2));





